﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WpfApplication1
{
	class MyNotifyIcon : IDisposable
    {
        public NotifyIcon myNotifyIcon;

        public delegate void MouseLeaveHandler();
        public event MouseLeaveHandler MouseDoubleClick;
        public MyNotifyIcon()
        {
            myNotifyIcon = new NotifyIcon();
            System.IO.Stream iconStream = System.Windows.Application.GetResourceStream(new Uri("pack://application:,,/Images/fb_icon_online.ico")).Stream;
            myNotifyIcon.Icon = new System.Drawing.Icon(iconStream);
            myNotifyIcon.Visible = true;
            myNotifyIcon.MouseDoubleClick += new MouseEventHandler(inside_myNotifyIcon_MouseDoubleClick);

            
        }
        public void inside_myNotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MouseDoubleClick();
        }
        #region IDisposable Members

        /// <summary>
        /// Standard IDisposable interface implementation. If you dont dispose the windows notify icon, the application
        /// closes but the icon remains in the task bar until such time as you mouse over it.
        /// </summary>
        private bool _IsDisposed = false;

        ~MyNotifyIcon()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            // Tell the garbage collector not to call the finalizer
            // since all the cleanup will already be done.
            GC.SuppressFinalize(true);
        }

        protected virtual void Dispose(bool IsDisposing)
        {
            if (_IsDisposed)
                return;

            if (IsDisposing)
            {
                myNotifyIcon.Dispose();
            }

            // Free any unmanaged resources in this section
            _IsDisposed = true;
        }
        #endregion

    }
}